package com.fr.report.highlight;

import com.fr.base.Style;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.CellElement;
import com.fr.report.Report;
import com.fr.report.script.Calculator;
import java.awt.Color;
import java.util.Iterator;

public class BackgroundHighlightAction extends AbstractHighlightAction
{
  private Background background = ColorBackground.getInstance(Color.white);
  private int scope = 0;

  public BackgroundHighlightAction()
  {
  }

  public BackgroundHighlightAction(Background paramBackground, int paramInt)
  {
    this.background = paramBackground;
    this.scope = paramInt;
  }

  public Background getBackground()
  {
    return this.background;
  }

  public void setBackground(Background paramBackground)
  {
    this.background = paramBackground;
  }

  public int getScope()
  {
    return this.scope;
  }

  public void setScope(int paramInt)
  {
    this.scope = paramInt;
  }

  public void action(CellElement paramCellElement, Calculator paramCalculator)
  {
    if (paramCellElement == null)
      return;
    Report localReport = paramCalculator.getCurrentReport();
    switch (getScope())
    {
    case 1:
      if (localReport == null)
        return;
      int i = paramCellElement.getRow();
      Iterator localIterator1 = localReport.getRow(i);
      while (true)
      {
        if (!(localIterator1.hasNext()))
          return;
        modifyBackground((CellElement)localIterator1.next(), this.background);
      }
    case 2:
      if (localReport == null)
        return;
      int j = paramCellElement.getColumn();
      Iterator localIterator2 = localReport.getColumn(j);
      while (true)
      {
        if (!(localIterator2.hasNext()))
          return;
        modifyBackground((CellElement)localIterator2.next(), this.background);
      }
    }
    modifyBackground(paramCellElement, this.background);
  }

  private void modifyBackground(CellElement paramCellElement, Background paramBackground)
  {
    if (paramCellElement == null)
      return;
    Style localStyle = paramCellElement.getStyle();
    paramCellElement.setStyle(localStyle.deriveBackground(this.background));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    BackgroundHighlightAction localBackgroundHighlightAction = (BackgroundHighlightAction)super.clone();
    localBackgroundHighlightAction.setBackground((Background)getBackground().clone());
    return localBackgroundHighlightAction;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ("Background".equals(str2))
        setBackground(BaseXMLUtils.readBackground(paramXMLableReader));
      if ("Scope".equals(str2))
      {
        String str1;
        if ((str1 = paramXMLableReader.getAttr("val")) != null)
          setScope(Integer.parseInt(str1));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (this.background != null)
      BaseXMLUtils.writeBackground(paramXMLPrintWriter, getBackground());
    if (getScope() != 0)
      paramXMLPrintWriter.startTAG("Scope").attr("val", getScope()).end();
  }
}